import Vue from "vue";
import Vuex from "vuex";
import utils from "@/assets/js/utils"; //载入更新路由方法
Vue.use(Vuex);

const state = {
  userList: JSON.parse(localStorage.getItem("userList")) ? JSON.parse(localStorage.getItem("userList")) : {patrolGroupNameList:[],roles:[],}, //用户信息
  token: localStorage.getItem("userList") ? JSON.parse(localStorage.getItem("userList")).appToken : '',
  oldPage: false, //false 常规人版本 true 适老版
  versions: '1.0.72',//版本号
  _user_id: '',//政务网用户id
  lng: 106.445122,
  lat: 29.822616,
  address: '北培区',
  appType: process.env.NODE_ENV,//development test production 
};

const mutations = {
  /**用户信息及token值*/
  SET_USERINFO(state, userinfo) {
    localStorage.setItem("userinfo", JSON.stringify(userinfo));
    localStorage.setItem("token", userinfo.accessToken.access_token);
    state.userinfo = userinfo;
    state.token = userinfo.accessToken.access_token;
  },
  /**改变页面样式版本*/
  SET_oldPage(state, oldPage) {
    state.oldPage = oldPage
    // if (state.oldPage) {
    //   document.querySelector('html').style.fontSize = '22.4vw'
    // } else {
    //   document.querySelector('html').style.fontSize = '13.33vw'
    // }
  },

};

const actions = {
  /**用户信息*/
  SET_USERINFO({
    commit
  }, userinfo) {
    commit("SET_USERINFO", userinfo);
  },

};


export default new Vuex.Store({
  state,
  mutations,
  actions
});